<?php

class Rapide_ACL_Loader implements Rapide_ACL_Loader_Interface {
	private
		$_aPrimaryRole,
		$_aPrimaryRules;

	public function setOptions(array $aPrimaryRole, array $aPrimaryRules) {
		$this->_aPrimaryRole = $aPrimaryRole;
		$this->_aPrimaryRules = $aPrimaryRules;
	}

	public function loadRules(Rapide_ACL $oACL) {
		$oUser = new Rapide_User;
		
		if(!$oUser->isAuthenticated()) {			
			$oACL->setRole($this->_aPrimaryRole, true);
		}
		else {
			$oACL->setRole($oUser->getRole());
		}
		
		if($oACL->aRole['root']) {
			$oACL->setState(Rapide_ACL::ACL_ALLOW_ALL);
		}
		else {
			$aAccessRules = $oUser->isAuthenticated() ? $oUser->getAccessRules() : $this->_aPrimaryRules;
			
			foreach($aAccessRules as $aRule) {
				$oACL->insertRule($aRule[0], $aRule[1]);
			}
		}
	}

}

?>